package com.ye.zcswzlms.controller;

import com.ye.zcswzlms.entity.Users;
import com.ye.zcswzlms.service.impl.LostpropertyServiceImpl;
import com.ye.zcswzlms.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 叶德辉
 * @since 2020-12-10
 */
@RestController
@RequestMapping("/lostproperty")
public class LostpropertyController {
    @Autowired
    LostpropertyServiceImpl lostpropertyService;
    @Autowired
    UsersServiceImpl usersService;
    @GetMapping ("/lostInfoInsert")
    boolean lostInsert(String src,String type,String userId,String lostPropertyName,String descript,String time,String location,String divid,String username,String tel){
        boolean i = lostpropertyService
                .LostpropertyInsert(src, userId, lostPropertyName, descript, LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), location, type, divid);
        if (usersService.checkReRegister(userId)==-1){
            if (usersService.userInsert(userId,username,tel)){
                return true;
            }else {
                return false;
            }
        }
        return true;
    }
    @GetMapping ("/FoundInsert")
    boolean FoundInsert(String src,String type,String userId,String lostPropertyName,String descript,String time,String location,String divid,String username,String tel){
        boolean i = lostpropertyService
                .LostpropertyInsert(src, userId, lostPropertyName, descript, LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), location, type, divid);
        if (usersService.checkReRegister(userId)==-1){
            if (usersService.userInsert(userId,username,tel)){
                return true;
            }else {
                return false;
            }
        }
        return true;
    }
}
